package com.leetcode.algorithm.y22.m07.w3;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

import com.leetcode.algorithm.common.Node;

class Question0429Solution01 {

	public List<List<Integer>> levelOrder(Node root) {
		List<List<Integer>> retList = new ArrayList<>();
		if (root == null) {
			return retList;
		}
		Queue<Node> queue = new LinkedList<>();
		queue.add(root);

		while (!queue.isEmpty()) {
			int len = queue.size();
			List<Integer> list = new ArrayList<>(len);
			retList.add(list);
			for (int i = 0; i < len; i++) {
				Node node = queue.poll();
				list.add(node.val);
				for (Node tmp : node.children) {
					queue.add(tmp);
				}
			}

		}

		return retList;
	}

}